SDK Guide
The JellyFaaS SDK simplifies working with the JellyFaaS API. It provides a Client
class which handles authentication and functions to simplify creating HTTP requests to the API. It also provides additional validation and checks of your requests, to prevent making invalid function calls, which would otherwise consume API credits.
API Credits
The cloud functions used in the examples below will not use your credits. Click here to get an secret key.
Here is a walk through using the Hello World
function.
1. Creating a Config object
The first step is to create your config object and parse your JellyFaaS secret key into it. The config handles keys and authorization.
2. Creating the Client
After that, you can create the client, and parse the newly created 'config' object into it:
3. Looking up a function
To look up a function, you must use the function's short name to find it. Provided all the previous steps are complete, add the following:
4. Setting the request query parameters & body
Once you've called 'lookup' on your client object, you can now set your request. Depending on the function, you may need to set query parameters, a body, or both. See the function schema for details.
4.1 Setting query parameters
4.2 Setting the body
a. Sending JSON data
If the function accepts a JSON format body, use the following syntax.
b. Sending files
If the function accepts a file input body, use the following syntax.
6. Invoking the function
You are ready to call your function! Simply call invoke()
and your function will be called.
const {Config, Client} = require('jellyfaas')
query_params = {
"rating": "PG",
"score": "5.8"
}
async function run() {
let config = await new Config("<JELLYFAAS_SECRET>") // Construct Config
let client = await new Client(config) // Construct Client
await client.lookupFunction("suggestmovie") // Lookup function
client.setFunctionQueryParams(query_params) // Set query params
let resp = await client.invoke(null, false) // invoke (overriding validation)
console.log(resp)
}
run()
Error Handling
The JellyFaaS SDK provides custom exceptions for different error scenarios. Below is a description of each error type and where to expect it to be thrown for each SDK:
-
jellyfaas.AuthenticationFailedException
Thrown when your credentials cannot be verified during config object creation.
-
jellyfaas.FunctionLookupException
Occurs during the function look up stage. This could be due to the function not existing.
-
jellyfaas.SetRequestException
This can be down to the query parameters being incorrect and therefore not lining up with the function's query parameter schema. Or, this can be due to the input body not matching the functions input schema.
-
jellyfaas.InvocationException
Next Steps
- Create your first function
- Get started with our cli tool
- Get your Secret key